package com.marketingexpert.controller.streammgnt;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.domain.User;
import com.marketingexpert.service.snsmgnt.SnsServiceFactory;
import com.marketingexpert.service.usermgnt.UserService;

public class GetTXRtCtCountController implements Controller {

private SnsServiceFactory snsServiceFactory;

private UserService userService;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		response.setContentType("application/x-json;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0);  
		PrintWriter out = response.getWriter(); 	
		
		String messageId = request.getParameter("messageId");
		String weiboUserId = request.getParameter("weiboUserId");
		
		User u = getUserService().queryUserByUId(weiboUserId);
		
		JSONArray jsonArray = getSnsServiceFactory().getService(SnsServiceFactory.TECENT).getRtCtCounts(u.getAccessToken(),u.getSecret(),messageId);
		
		out.print(jsonArray);
		
		return null;
	}

	public SnsServiceFactory getSnsServiceFactory() {
		return snsServiceFactory;
	}

	public void setSnsServiceFactory(SnsServiceFactory snsServiceFactory) {
		this.snsServiceFactory = snsServiceFactory;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	

}
